#include "matrix.h"

template<typename T> 
CMatrix<T>::CMatrix(unsigned nrows, unsigned ncols): data_ (nrows)
{
	if (nrows==0 || ncols==0)
		throw BadSize();
	for (unsigned i=0; i<nrows; ++i)
		data_[i].resize(ncols);
}

template<typename T>
inline unsigned CMatrix<T>::nrows() const
{
	return data_.size();
}

template<typename T>
inline unsigned CMatrix<T>::ncols() const
{
	return data_[0].size();
}

template<typename T>
inline T& CMatrix<T>::operator() (unsigned row, unsigned col)
{
	if (row>nrows() || col>ncols() || row==0 || col==0)
		throw BoundsViolations();
	return data_[row-1][col-1];         /// indexes lies form 1, not from 0 like in programming
}

template<typename T>
inline const T& CMatrix<T>::operator()(unsigned row, unsigned col) const
{
	if (row>nrows() || col>ncols() || row==0 || col==0)
		throw BoundsViolations();
	return data_[row-1][col-1];
}

template<typename T>
void CMatrix<T>::Resize(unsigned nrows,unsigned ncols)
{
	if (nrows==0 || ncols==0)
		throw BadSize();
	data_.resize(nrows);
	for (unsigned i=0; i<nrows; ++i)
		data_[i].resize(ncols);
};
